home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / BIOSCOM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.4 KB  |  59 lines

  1. /* bioscom.c --- p556 */
  2. #include <stdio.h >
  3. #include <bios.h>
  4. #define  COM1        0             /* Change this to 1 for COM2 */
  5. #define  COM_INIT    0
  6. #define  COM_SEND    1
  7. #define  COM_RECEIVE 2
  8. #define  COM_STATUS  3
  9. #define  KEYBRD_READ 0
  10. #define  KEYBRD_READY 1
  11. main()
  12. {
  13.     int c;
  14.     unsigned service, data, status;
  15.     data = (0x03 | 0x00 |0x00 | 0x40);
  16.     bioscom(COM_INIT,data, COM1);
  17.     printf("Connecting to serial port 1. Type 'q' to exit\n");
  18.     while(1)
  19.     {
  20.             /* First see if "DATA READY" flag is set. If yes read
  21.              * character from serial port. */
  22.     status =0x100 &
  23.     bioscom(COM_STATUS, 0, COM1);
  24.     if( status == 0x100)
  25.     {
  26.             /* If there is a character, get it and display it */
  27.         c =0xff &
  28.         bioscom(COM_RECEIVE, 0, COM1);
  29.         printf("%c", c);
  30.     }
  31.                 /* Now check if any key has been pressed */
  32.     if(bioskey(KEYBRD_READY))
  33.     {
  34.                 /* If yes,read the keyboard buffer */
  35.     c = bioskey(KEYBRD_READ) & 0xff;
  36.     if((c== 'q') || (c == 'Q'))
  37.     {
  38.                 /* Exit if it's a 'q' or a 'Q'*/
  39.         printf("Exiting...\n");
  40.         exit(0);
  41.     }
  42.             /* Else, wait until "transmit holding register empty"
  43.              * flag is set. Once it's set, send out character to
  44.              * serial port. */
  45.     status =0x2000 &
  46.     bioscom(COM_STATUS, 0, COM1);
  47.     while (status != 0x2000)
  48.     {
  49.         status = 0x2000 &
  50.                 bioscom(COM_STATUS, 0,COM1);
  51.      }
  52.     bioscom(COM_SEND, c, COM1);
  53.     if(( status & 0x8000) == 0x8000)
  54.     {
  55.        printf("Error sending: %c\n", c);
  56.     }
  57.      }
  58.    }
  59. }